home *** CD-ROM | disk | FTP | other *** search
- class PlayerCar
- {
- var pos;
- var vel;
- var acc;
- var maxVel;
- var sEnemy;
- var energy;
- var blinkInd;
- var exitDelay;
- var deadTime;
- var bDestroyed;
- var bEnter;
- var bExit;
- var bShield;
- var bAllowShooting;
- var mcCanvas;
- var mcCar;
- var width;
- var height;
- var bSkid;
- var bPuddle;
- var skidRot;
- var weaponFrame;
- var mcWeapon;
- var mcWeaponArea;
- var skidDir;
- function PlayerCar(newPos, mcCanvasNew, sEnemyNew)
- {
- this.pos = newPos.clone();
- this.vel = new flash.geom.Point(0,0);
- this.acc = new flash.geom.Point(0,0);
- this.maxVel = 20;
- this.sEnemy = sEnemyNew;
- this.energy = 100;
- this.blinkInd = 0;
- this.exitDelay = 10;
- this.deadTime = 0;
- this.bDestroyed = false;
- this.bEnter = true;
- this.bExit = false;
- this.bShield = false;
- this.bAllowShooting = true;
- this.mcCanvas = mcCanvasNew;
- this.mcCar = this.mcCanvas.attachMovie("player car","mcCar",999);
- this.setWeapon();
- this.width = 48;
- this.height = 48;
- this.bSkid = false;
- this.bPuddle = false;
- this.draw();
- }
- function step(Void)
- {
- if(this.bDestroyed)
- {
- if(this.deadTime-- == 0)
- {
- this.bDestroyed = false;
- this.die();
- }
- return undefined;
- }
- if(this.bEnter)
- {
- if(this.pos.y < 50)
- {
- this.pos.y += 5;
- }
- else
- {
- this.pos.y = 50;
- this.showWeapon();
- this.bEnter = false;
- }
- return undefined;
- }
- if(this.bExit)
- {
- this.vel.x = 0;
- if(this.exitDelay-- <= 0)
- {
- if(this.pos.y < 500)
- {
- this.pos.y += 25;
- }
- else
- {
- this.pos.y = 500;
- Game.getInstance().onPlayerOut();
- }
- }
- return undefined;
- }
- if(this.bSkid)
- {
- if(this.skidRot < 360)
- {
- this.skidRot += 18;
- }
- else
- {
- this.bSkid = false;
- this.skidRot = 360;
- }
- }
- else
- {
- this.keyControl();
- }
- this.vel.x += this.acc.x;
- this.vel.y += this.acc.y;
- if(this.acc.x == 0)
- {
- this.vel.x *= 0.7;
- }
- if(this.vel.y < 0)
- {
- this.vel.y = 0;
- }
- else if(this.vel.y > this.maxVel)
- {
- this.vel.y = this.maxVel;
- }
- if(this.vel.x < (- this.maxVel) / 2)
- {
- this.vel.x = (- this.maxVel) / 2;
- }
- else if(this.vel.x > this.maxVel / 2)
- {
- this.vel.x = this.maxVel / 2;
- }
- this.pos.x += this.vel.x * this.vel.y / this.maxVel;
- this.pos.y = 50 + 70 * this.vel.y / this.maxVel;
- if(this.pos.x < this.width / 2)
- {
- this.pos.x = this.width / 2;
- }
- else if(this.pos.x > Game.screenW - this.width / 2)
- {
- this.pos.x = Game.screenW - this.width / 2;
- }
- if(this.blinkInd > 0)
- {
- this.blinkInd = this.blinkInd - 1;
- this.blink();
- }
- if(!this.bAllowShooting)
- {
- if(this.weaponFrame == this.mcWeapon.mcAnim._currentframe)
- {
- this.bAllowShooting = true;
- this.mcWeaponArea = undefined;
- }
- this.weaponFrame = this.mcWeapon.mcAnim._currentframe;
- if(this.mcWeaponArea == undefined)
- {
- this.mcWeaponArea = this.mcWeapon.mcAnim.mcHitArea;
- }
- }
- }
- function draw(Void)
- {
- this.mcCar._x = this.pos.x;
- this.mcCar._y = Game.screenH - this.pos.y;
- if(!this.bSkid)
- {
- this.mcCar._rotation = this.vel.x * Math.ceil(this.vel.y / this.maxVel);
- }
- else
- {
- this.mcCar._rotation = this.skidRot * this.skidDir;
- }
- }
- function keyControl(Void)
- {
- var _loc2_ = 38;
- var _loc6_ = 40;
- var _loc3_ = 37;
- var _loc4_ = 39;
- var _loc5_ = 32;
- var _loc7_ = 88;
- var _loc8_ = 90;
- this.acc.y = 0;
- if(Key.isDown(_loc2_))
- {
- this.acc.y = 0.5;
- }
- else if(Key.isDown(_loc6_))
- {
- this.acc.y = -0.5;
- }
- this.acc.x = 0;
- if(Key.isDown(_loc3_))
- {
- this.acc.x = -2;
- }
- else if(Key.isDown(_loc4_))
- {
- this.acc.x = 2;
- }
- if(Key.isDown(_loc5_) && this.bAllowShooting)
- {
- this.bAllowShooting = false;
- this.shoot();
- }
- }
- function getRect(Void)
- {
- var _loc2_ = this.mcCar.getRect(this.mcCanvas);
- return new flash.geom.Rectangle(_loc2_.xMin,_loc2_.yMin,_loc2_.xMax - _loc2_.xMin,_loc2_.yMax - _loc2_.yMin);
- }
- function reactionOnShoulder(bmpShoulder)
- {
- var _loc6_ = Math.sqrt(this.width * this.width + this.height * this.height) / 2;
- var _loc4_ = new flash.geom.Point(this.mcCar._x - this.width / 2,this.mcCar._y - this.height / 2);
- var _loc2_ = new flash.geom.Point(this.mcCar._x + this.width / 2,this.mcCar._y - this.height / 2);
- if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,_loc4_))
- {
- this.vel.x = this.vel.y / 2;
- if(this.vel.x < 2)
- {
- this.vel.x = 2;
- }
- this.pos.x += this.vel.x;
- var _loc3_ = 10 * Math.ceil(this.vel.y / this.maxVel * 2);
- this.getDamage(_loc3_);
- Sounds.playSound("carCrash");
- }
- else if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,_loc2_))
- {
- this.vel.x = (- this.vel.y) / 2;
- if(this.vel.x > -2)
- {
- this.vel.x = -2;
- }
- this.pos.x += this.vel.x;
- _loc3_ = 10 * Math.ceil(this.vel.y / this.maxVel * (!Application.bEasy ? 3 : 2));
- this.getDamage(_loc3_);
- Sounds.playSound("carCrash");
- }
- }
- function getDamage(damage)
- {
- if(this.bEnter || this.bExit || this.bShield)
- {
- return undefined;
- }
- if(this.blinkInd == 0)
- {
- this.energy -= damage;
- }
- if(this.energy <= 0)
- {
- this.energy = 0;
- this.deadTime = 10;
- this.bDestroyed = true;
- this.mcCar.gotoAndStop("dead");
- }
- else
- {
- this.blinkInd = 30;
- }
- Game.getInstance().setEnergyMeter(this.energy);
- }
- function die(Void)
- {
- this.vel.x = 0;
- this.vel.y = 0;
- Game.getInstance().loseLife();
- }
- function blink(Void)
- {
- var _loc3_ = undefined;
- if(this.blinkInd % 2 == 1)
- {
- var _loc2_ = Math.round(255 * this.blinkInd / 30);
- _loc3_ = new flash.geom.ColorTransform(1,1,1,1,_loc2_,_loc2_,_loc2_,0);
- }
- else
- {
- _loc3_ = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
- }
- var _loc4_ = new flash.geom.Transform(this.mcCar);
- _loc4_.colorTransform = _loc3_;
- }
- function showWeapon(Void)
- {
- this.mcWeapon.mcAnim.gotoAndPlay("show");
- }
- function hideWeapon(Void)
- {
- this.mcWeapon.mcAnim.gotoAndPlay("hide");
- }
- function shoot(Void)
- {
- this.mcWeapon.mcAnim.gotoAndPlay("shot");
- this.weaponFrame = this.mcWeapon.mcAnim._currentframe + 1;
- if(this.sEnemy == "sainsbury" || this.sEnemy == "moreThan" || this.sEnemy == "admiral")
- {
- this.mcWeaponArea = Game.getInstance().createShot(this.sEnemy);
- }
- }
- function checkObstacle(mcObstacle)
- {
- var _loc2_ = Game.getInstance().sEnemy;
- if(mcObstacle.hitTest(this.mcCar._x,this.mcCar._y))
- {
- this.getDamage(30);
- }
- }
- function checkPuddle(refPuddle)
- {
- if(this.mcCar.mcWheels.hitTest(refPuddle.mcPuddle))
- {
- if(refPuddle.type == 0 && !this.bSkid)
- {
- if(this.vel.y > 2 && !this.bPuddle)
- {
- this.vel.y *= 0.6;
- this.bSkid = true;
- this.bPuddle = true;
- this.skidRot = 0;
- if(this.vel.x > 0)
- {
- this.skidDir = 1;
- }
- else
- {
- this.skidDir = -1;
- }
- Sounds.playSound("tyrescreech");
- }
- }
- else if(refPuddle.type == 1)
- {
- if(this.vel.y > 2)
- {
- this.vel.y *= 0.9;
- }
- if(!this.bPuddle)
- {
- this.bPuddle = true;
- Sounds.playSound("splash");
- }
- }
- }
- else
- {
- this.bPuddle = false;
- }
- }
- function remove(Void)
- {
- this.mcCar.removeMovieClip();
- false;
- }
- function setWeapon(Void)
- {
- this.mcWeapon = this.mcCar.mcWeapon;
- this.mcWeapon.gotoAndStop(this.sEnemy);
- }
- function newLife(Void)
- {
- this.mcCar.gotoAndStop("alive");
- this.energy = 100;
- this.bEnter = true;
- this.pos.y = -50;
- this.setWeapon();
- this.bPuddle = false;
- }
- function setShieldOn(Void)
- {
- this.bShield = true;
- var _loc5_ = 16777215;
- var _loc11_ = 0.8;
- var _loc8_ = 8;
- var _loc7_ = 8;
- var _loc9_ = 50;
- var _loc3_ = 1;
- var _loc6_ = false;
- var _loc10_ = false;
- var _loc4_ = new flash.filters.GlowFilter(_loc5_,_loc11_,_loc8_,_loc7_,_loc9_,_loc3_,_loc6_,_loc10_);
- var _loc2_ = new Array();
- _loc2_.push(_loc4_);
- this.mcCar.filters = _loc2_;
- }
- }
-